package com.ee.chat.api.controller;

import com.ee.chat.api.service.IUserService;
import com.ee.chat.api.vo.UserAuditVO;
import com.ee.chat.common.bean.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author Shane
 * @Date 2019/7/28 22:59
 */
@RestController
@RequestMapping("user")
public class UserController {
    private Logger log = LoggerFactory.getLogger(UserController.class);

    @Resource
    IUserService userService;

    /**
     * 获取用户信息
     * @Author Shane
     * @Date 2019/8/816:34
     * @param
     * @return
     **/
    @RequestMapping("getUserInfo")
    public Result getUserInfo(@RequestParam String token){
        try {
            return userService.getUserInfo(token);
        } catch(Exception e){
            log.error("【获取用户信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户访问记录
     * @Author Shane
     * @Date 2019/8/910:31
     * @param type  访问类型，0-我访问的  1-访问我的
     * @return
     **/
    @RequestMapping("getUserAccessLogs")
    public Result getUserAccessLogs(@RequestParam String token, @RequestParam Integer type,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer limit){
        try {
            return userService.getUserAccessLogs(token, type, page, limit);
        } catch (Exception e){
            log.error("【获取用户访问记录错误】", e);   
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户动态
     * @Author Shane
     * @Date 2019/8/911:56
     * @param 
     * @return
     **/
    @RequestMapping("getUserDynaimcs")
    public Result getUserDynaimcs(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer limit){
        try {
            return userService.getUserDynaimcs(token, page, limit);
        } catch (Exception e){
            log.error("【获取用户动态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户朋友
     * @Author Shane
     * @Date 2019/8/912:08
     * @param type  朋友，0-关注  1-粉丝
     * @param toUserId  当toUserId不为空时，则获取的是toUserId的朋友
     * @return
     **/
    @RequestMapping("getUserFriends")
    public Result getUserFriends(@RequestParam String token, Integer toUserId, @RequestParam Integer type,
                                 @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer limit){
        try {
            return userService.getUserFriends(token, toUserId, type, page, limit);
        } catch (Exception e){
            log.error("【获取用户朋友错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 设置勿扰模式
     * @Author Shane
     * @Date 2019/8/916:52
     * @param dnd   勿扰模式，0-关闭  1-开启
     * @return
     **/
    @RequestMapping("setDND")
    public Result setDND(@RequestParam String token, @RequestParam Integer dnd){
        try {
            return userService.setDND(token, dnd);
        } catch (Exception e){
            log.error("【设置勿扰模式错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取认证资料
     * @Author Shane
     * @Date 2019/8/10 19:34
     * @param
     * @return
     */
    @RequestMapping("getAuditInfo")
    public Result getAuditInfo(@RequestParam String token){
        try {
            return userService.getAuditInfo(token);
        } catch (Exception e){
            log.error("【获取认证资料错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取城市行政区划
     * @Author Shane
     * @Date 2019/8/1912:25
     * @param
     * @return
     **/
    @RequestMapping("getAreaLib")
    public Result getAreaLib(@RequestParam String token){
        try {
            return userService.getAreaLib(token);
        } catch (Exception e){
            log.error("【获取城市行政区划错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取标签库
     * @Author Shane
     * @Date 2019/8/1912:26
     * @param host  用户类型，0-普通用户  1=主播用户
     * @return
     **/
    @RequestMapping("getLableLib")
    public Result getLableLib(@RequestParam String token, @RequestParam(required = false) Integer host){
        try {
            return userService.getLableLib(token, host);
        } catch (Exception e){
            log.error("【获取标签库错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取星座库
     * @Author Shane
     * @Date 2019/8/2019:36
     * @param
     * @return
     **/
    @RequestMapping("getUSSLib")
    public Result getUSSLib(@RequestParam String token){
        try {
            return userService.getUSSLib(token);
        } catch (Exception e){
            log.error("【获取星座信息库错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取职业库
     * @Author Shane
     * @Date 2020/4/1 17:36
     * @param
     * @return
     */
    @RequestMapping("getProLib")
    public Result getProLib(@RequestParam String token){
        try {
            return userService.getProLib(token);
        } catch (Exception e){
            log.error("【获取职业库错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取情感库
     * @Author Shane
     * @Date 2020/4/1 17:37
     * @param
     * @return
     */
    @RequestMapping("getEmLib")
    public Result getEmLib(@RequestParam String token){
        try {
            return userService.getEmLib(token);
        } catch (Exception e){
            log.error("【获取情感库错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 保存认证资料
     * @Author Shane
     * @Date 2019/8/9 23:33
     * @param userAuditVO   资料对象
     * @return
     */
    @RequestMapping("saveAuditInfo")
    public Result saveAuditInfo(UserAuditVO userAuditVO){
        try {
            return userService.saveAuditInfo(userAuditVO);
        } catch (Exception e){
            log.error("【保存认证资料错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 加关注/取消关注
     * @Author Shane
     * @Date 2019/10/5 16:43
     * @param
     * @return
     */
    @RequestMapping("focus")
    public Result focus(@RequestParam String token, @RequestParam Integer toUserId, @RequestParam Integer type){
        try {
            return userService.focus(token, toUserId, type);
        } catch (Exception e){
            log.error("【加关注/取消关注错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 添加招呼内容
     * @Author Shane
     * @Date 2019/10/8 9:54
     * @param content   招呼内容
     * @return
     */
    @RequestMapping("addCallContent")
    public Result addCallContent(@RequestParam String token, @RequestParam String content){
        try {
            return userService.addCallContent(token, content);
        } catch (Exception e){
            log.error("【添加招呼内容错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 保存招呼内容
     * @Author Shane
     * @Date 2020/8/19 17:29
     * @param contents 内容json数组字符串，[{"id": 1, "orderId": 1}]
     * @return
     */
    @RequestMapping("saveCallContent")
    public Result saveCallContent(@RequestParam String token, @RequestParam String contents){
        try {
            return userService.saveCallContent(token, contents);
        } catch (Exception e){
            log.error("【保存招呼内容错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 删除招呼内容
     * @Author Shane
     * @Date 2019/10/8 9:59
     * @param
     * @return
     */
    @RequestMapping("delCallContent")
    public Result delCallContent(@RequestParam String token, @RequestParam String ids){
        try {
            return userService.delCallContent(token, ids);
        } catch (Exception e){
            log.error("【删除招呼内容错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取主播通话价格列表
     * @Author Shane
     * @Date 2019/10/8 18:14
     * @param
     * @return
     */
    @RequestMapping("getCharge")
    public Result getCharge(@RequestParam String token){
        try {
            return userService.getCharge(token);
        } catch (Exception e){
            log.error("【获取通话价格错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 设置通话价格
     * @Author Shane
     * @Date 2019/10/8 18:21
     * @param chargeId  价格id
     * @return
     */
    @RequestMapping("setCharge")
    public Result setCharge(@RequestParam String token, @RequestParam Integer chargeId){
        try {
            return userService.setCharge(token, chargeId);
        } catch (Exception e){
            log.error("【设置通话价格错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取邀请信息
     * @Author Shane
     * @Date 2019/10/13 23:33
     * @param
     * @return
     */
    @RequestMapping("getInviteInfo")
    public Result getInviteInfo(@RequestParam String token){
        try {
            return userService.getInviteInfo(token);
        } catch (Exception e){
            log.error("【获取邀请信息错误】", e);
        }
        return Result.returnFailure();
    }
    
    /**
     * 获取邀请的用户
     * @Author Shane
     * @Date 2019/10/13 23:35
     * @param 
     * @return 
     */
    @RequestMapping("getInviteUser")
    public Result getInviteUser(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer limit){
        try {
            return userService.getInviteUser(token, page, limit);
        } catch (Exception e){
            log.error("【获取邀请的用户错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取邀请奖励
     * @Author Shane
     * @Date 2019/10/13 23:37
     * @param
     * @return
     */
    @RequestMapping("getInviteAward")
    public Result getInviteAward(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer limit){
        try {
            return userService.getInviteAward(token, page, limit);
        } catch (Exception e){
            log.error("【获取邀请奖励错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 查询通话用户的信息
     * @Author Shane
     * @Date 2019/11/14 20:40
     * @param toUserId  通话的用户id
     * @return
     **/
    @RequestMapping("getCellUserInfo")
    public Result getCellUserInfo(@RequestParam String token, @RequestParam Integer toUserId){
        try {
            return userService.getCellUserInfo(token, toUserId);
        } catch (Exception e){
            log.error("【获通话用户信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 设置隐私模式
     * @Author Shane
     * @Date 2020/4/3 12:14
     * @param
     * @return
     */
    @RequestMapping("setPrivacy")
    public Result setPrivacy(@RequestParam String token, @RequestParam Integer privacy){
        try {
            return userService.setPrivacy(token, privacy);
        } catch (Exception e){
            log.error("【设置隐私模式错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 设置同城状态
     * @param token
     * @param local 同城状态，0-开启  1-关闭
     * @return
     */
    @RequestMapping("setLocal")
    public Result setLocal(@RequestParam String token, @RequestParam Integer local){
        try {
            return userService.setLocal(token, local);
        } catch (Exception e){
            log.error("【设置同城状态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取邀请链接
     * @param token
     * @return
     */
    @RequestMapping("getInviteUrl")
    public Result getInviteUrl(@RequestParam String token){
        try {
            return userService.getInviteUrl(token);
        } catch (Exception e){
            log.error("【获取邀请链接】", e);
        }
        return Result.returnFailure();
    }
}
